<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="oneroom.admin.code.codeModel" %>
<jsp:useBean id="code" scope="page" class="oneroom.admin.code.codeDao" />
<%
	/*
	페이징 관련 
	*/
	String pageName = "main_list.jsp";
	int		giSelectPage  	= Integer.parseInt(request.getParameter("txtSelectPage") == null ? "0" :request.getParameter("txtSelectPage"));			//현재 선택된 페이지 저장
	int		giSelectBlock 	= Integer.parseInt(request.getParameter("txtSelectBlock") == null ? "0" :request.getParameter("txtSelectBlock"));			//현재 선택된 블락페이지 저장
	String	searchGubn		= request.getParameter("searchGubn")	== null ? "" : request.getParameter("searchGubn");
	String	searchValue		= request.getParameter("searchValue")	== null ? "" : request.getParameter("searchValue");

	int     giCount       	= 0;			//리스트 for문 break문에 사용
	int     giRecordcnt   	= 0;			//리스트의 카운터에 사용
	int     giPageSize    	= 10;  			// 한페이지에 나타내고자 하는 List수
	int     giBlockSize   	= 10;   		// Block의 수
	int     giCurPage     	= 1;   			// 현재 Page
	int     giCurBlock    	= 0;   			// 현재 Block
	int     giStartPos    	= 0;   			// 시작 List 위치
	int     giTotPage     	= 0;   			// 총 Page수
	int     giTotBlock    	= 0;   			// 총 Block수
	//  넘겨온 값 받기(List페이지 관련)...
	if ( giSelectPage  >  0 ) { 			// 선택된 Page값이 있을경우....     
		giCurPage  = giSelectPage;   	// 현재Page = 선택된Page 
		giCurBlock = giSelectBlock;  	// 블락page = 선택된 블락 page
	}
	//쿼리를 돌려서 가지고 오는 값
	List list = code.getList(searchGubn,searchValue, giSelectPage, giPageSize);
	if (list.size() > 0 ) {
		//전체 게시물 수
		giRecordcnt = code.getCount(searchGubn,searchValue); 			// 총 list 수
	}
	if (giRecordcnt > 0) {  // 조건에 맞는 값이 있으면....
		giTotPage  = giRecordcnt / giPageSize;
		if (giRecordcnt % giPageSize != 0) {
			giTotPage = giTotPage + 1;			// 총 Page수를 구한다...
		}
		giTotBlock = giTotPage / giBlockSize;
		if (giTotPage % giBlockSize != 0) {
			giTotBlock = giTotBlock + 1;		// 총 Block수를 구한다...
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>코드관리</title>
<script type="text/javascript" src="/admin/js/default.js"></script>
<script type="text/javascript" src="/admin/js/jquery-1.3.2.min.js"></script>
<link href="/admin/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
	function addComCodeRow() {
		document.getElementById("pattern_comcode_row").style.display = "";		
	}
	function hideComCode() {
		document.getElementById("pattern_comcode_row").style.display = "none";
	}
	function regComCode() {
		var frm = document.frm;
		if(frm.uescheck.checked == true){
			frm.useyn.value = "Y";
		}else{
			frm.useyn.value = "N";
		}
		frm.gubun.value = "I";
		frm.submit();
	}	
	function editComCode(cnt) {
		fillForm(cnt);
		var frm = document.frm;
		frm.gubun.value = "U";
		frm.submit();
	}
	function deleteComCode(cnt) {
		if (confirm("삭제하시겠습니까?")) {
			fillForm(cnt);
			var frm = document.frm;
			frm.gubun.value = "D";
			frm.submit();
		}
	}	
	function fillForm(cnt) {
		var code = document.getElementById("code"+cnt).value;
		var codename = document.getElementById("codename"+cnt).value;
		var comment = document.getElementById("comment"+cnt).value;
		var useyn = document.getElementById("useyn"+cnt).checked == true ? "Y" : "N";
		var frm = document.frm;
		frm.code.value = code;
		frm.codename.value = codename;
		frm.comment.value = comment;
		frm.useyn.value = useyn;
	}	
	function showDetail(hdrcode) {
		var frm = document.frm_dtl;
		frm.target	="data_iframe";
		frm.action	="list.jsp";
		frm.hdrcode.value = hdrcode;
		frm.submit();
	}
//-->
</script>
</head>
<body>
<!-- Header  Start -->
<div id="bodywrap">
<div class="all-wrap">
<%@ include file="/admin/common/top.jsp" %>
<div id="right-wrap">
<%@ include file="/admin/common/navi.jsp" %>
<!--Contents Start-->
<div id="content">
<div class="path"><span>home</span> >  코드관리 </div>
<h4>코드관리</h4>
<p class="sub-text">코드관리 하실 수 있습니다.</p>
	<div class="btn-all-align2">
	<span class="btn-align"><input type="button" value="등록" class="btn-bg-gray" id="wrtBtn" onclick="addComCodeRow();" /></span>
	<br />
	</div>
	<form name="frm" method="post" action="dbx.jsp">
	<input type="hidden" name="gubun" value="">	
	<input type="hidden" name="useyn" value="">	
	<table class="list-normal" cellpadding="0" cellspacing="0" summary="code" >
	  <caption>코드 목록</caption>
	  <col width="10%" />
	  <col width="18%" />
	  <col width="20%" />
	  <col width="20%" />
	  <col width="12%" />
	  <col width="20%" />
	  <thead>
	    <tr>
	      <th scope="col" >No</th>
	      <th scope="col" >코드</th>
	      <th scope="col" >코드 명</th>
	      <th scope="col" >설명</th>
	      <th scope="col" >사용 여부</th>
	      <th scope="col" >관리</th>
	    </tr>
	  </thead>
	<tbody>	  
        <tr id="pattern_comcode_row" style="display: none;" style="border:0px" >
		  	<td>&nbsp;</td>
            <td><input type="text" id="code" name="code" value="" size="10%" maxlength="6"/></td>
            <td><input type="text" id="codename" name="codename" value="" size="20%" /></td>
            <td><input type="text" id="comment" name="comment" value="" size="20%" /></td>
            <td><input type="checkbox" id="uescheck" name="uescheck" checked /></td>
            <td><input type="button" class="btn_ch3" id="saveButton" value="저장" onclick="regComCode();" />
            	<input type="button" class="btn_ch3" id="cancelButton" value="취소" onclick="hideComCode();"/>
			</td>
        </tr>	
		<%
			if(list != null && list.size() > 0){
				giCount  = 1;
				giRecordcnt = giRecordcnt - ( giCurPage -1 ) * giPageSize;	
				giStartPos = ((giCurPage - 1) * giPageSize) + 1;
				for(int i = 0; i<list.size(); i++){
					codeModel model = (codeModel)list.get(i);
		%>
		<tr>
			<td><%=giRecordcnt %></td>
			<td onclick="showDetail('<%=model.getCode() %>')" style="cursor:pointer;"><input type="text" id="code<%=giCount %>" value="<%=model.getCode()%>" size="10%" maxlength="6" disabled="disabled"></td>
			<td><input type="text" id="codename<%=giCount %>" value="<%=model.getCodename() %>" size="20%" /></td>
			<td><input type="text" id="comment<%=giCount %>" value="<%=model.getComment() %>" size="20%" /></td>
			<td><input type="checkbox" id="useyn<%=giCount %>" <%if(model.getUseyn().equals("Y")){%>checked<%} %> /></td>
			<td><input type="button" class="btn_ch3" id="editButton" value="수정" onclick="editComCode('<%=giCount %>');" />
            	<input type="button" class="btn_ch3" id="deleteButton" value="삭제" onclick="deleteComCode('<%=giCount %>');"/>
            </td>
		</tr>
		<%
					giCount = giCount + 1;
					giRecordcnt = giRecordcnt - 1;
				}
			}else{
		%>
		<tr><td colspan="6">등록된 내용이 없습니다.</td></tr>
		<%
			}
		%>
	</tbody>
	</table>	
	</form>	
	<div class="page-num">
	<%@ include file="/admin/common/pages.jsp" %>
	</div>
	<div class="btn-all-align2">
	<span class="btn-align"><input type="button" value="등록" class="btn-bg-gray" id="wrtBtn" onclick="data_iframe.addComCodeRow();" /></span>
	</div>	
	<table class="list-normal" cellpadding="0" cellspacing="0" summary="EVENT" >
	  <caption>회원 목록</caption>
	  <col width="5%" />
	  <col width="10%" />
	  <col width="15%" />
	  <col width="15%" />
	  <col width="20%" />
	  <col width="10%" />
	  <col width="20%" />
	  <thead>
	    <tr>
	      <th scope="col" >No</th>
	      <th scope="col" >해더 코드</th>
	      <th scope="col" >코드</th>
	      <th scope="col" >코드 명</th>
	      <th scope="col" >설명</th>
	      <th scope="col" >사용 여부</th>
	      <th scope="col" >관리</th>
	    </tr>
	  </thead>
	</table>
	<iframe id="data_iframe" name="data_iframe" width="100%" height="320px" src="" name="test" allowtransparency="true" frameborder="0" scrolling="auto" ></iframe>	
    <form name="frm_dtl" id="frm_dtl" method="post">	
		<input type="hidden" name="hdrcode" value="" />
	</form>


</div>
<!--Contents End-->
</div>
</div>
<!--Footer Start-->
<%@ include file="/admin/common/bottom.jsp" %>
<!--Footer End-->		
</body>
</html>